/*
    Copyright 2000-2011 Francois de Bertrand de Beuvron

    This file is part of CoursBeuvron.

    CoursBeuvron is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CoursBeuvron is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CoursBeuvron.  If not, see <http://www.gnu.org/licenses/>.
 */

package fr.insa.beuvron.tps.m2.dessin2DV2;

import fr.insa.commun.Lire;

public class Point implements Figure {
    
    private double abscisse;

    private double ordonnee;
    
    public Point() {
    }
    
    public Point(double x,double y) {
        this.abscisse = x;
        this.ordonnee = y;
    }
    
    public static Point cree(double x,double y) {
       return new Point(x,y);
    }
    
    public static Point demande() {
       System.out.println("abscisse du point : ");
       double abs = Lire.d();
       System.out.println("ordonnée du point : ");
       double ord = Lire.d();
       return Point.cree(abs,ord);
    }
    
    public boolean egal(Point p2) {
       return (this.abscisse == p2.abscisse) && (this.ordonnee == p2.ordonnee);
    }
    
    @Override
    public String toString() {
        return "(" + this.abscisse + "," + this.ordonnee + ")";
    }

    public double getAbscisse() {
        return abscisse;
    }

    public void setAbscisse(double val) {
        this.abscisse = val;
    }

    public double getOrdonnee() {
        return ordonnee;
    }

    public void setOrdonnee(double val) {
        this.ordonnee = val;
    }

    @Override
    public double maxX() {
        return this.abscisse;
    }

    @Override
    public double minX() {
        return this.abscisse;
    }

    @Override
    public double maxY() {
        return this.ordonnee;
    }

    @Override
    public double minY() {
        return this.ordonnee;
    }
    
    @Override
    public double distance(Point p) {
        double dx = this.abscisse - p.abscisse;
        double dy = this.ordonnee - p.ordonnee;
        return Math.sqrt(dx*dx+dy*dy);
    }
  
    @Override
    public String jolieDescription(int niveau) {
        return Utils.indent("Point " + this.toString(), niveau*2);
    }
  
}
